package com.example.demo.leetcode.classics150;

import java.util.HashMap;
import java.util.Map;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _31无重复字符的最长子串
 * @description
 * @date 2023/07/18 16:38
 * <p>
 * ******************************************************
 */
public class _31无重复字符的最长子串 {


    public int lengthOfLongestSubstring(String s) {
        int length = s.length();
        int left = 0;
        int right = 0;
        int max = 0;

        while (right < length) {
            char curr = s.charAt(right);
            if (contains(s, left, right-1, curr)) {
                while (s.charAt(left) != curr) {
                    left++;
                }
                left++;
            }
            right++;
            max = Math.max(max, right - left);
        }
        return max;
    }

    private boolean contains(String s, int start, int end, Character c) {
        return s.substring(start, end + 1).indexOf(c) >= 0;
    }


    public static void main(String[] args) {
        _31无重复字符的最长子串 s = new _31无重复字符的最长子串();
        System.out.println(s.lengthOfLongestSubstring("abcabcbb"));
    }
}
